import type { BaseOrgModel } from '../basic';
import type { AuthModel } from './model/auth';
import type { UserModel } from './model/user';

import { ServicePrefixEnum } from '#/enums/commonEnum';
import { ContentTypeEnum } from '#/enums/httpEnum';

import { requestClient } from '../request';

/** 设置默认企业 */
export async function updateDefaultTenant(tenantId: string) {
  return requestClient.put<boolean>(
    `${ServicePrefixEnum.BASE}/anyone/updateDefaultTenant`,
    { tenantId },
    {
      headers: {
        'Content-Type': ContentTypeEnum.FORM_URLENCODED,
      },
    },
  );
}
/** 切换当前企业 */
export async function switchTenantAndOrg(
  tenantId: null | string,
  orgId?: null | string,
) {
  return requestClient.put<AuthModel.LoginResultVO>(
    `${ServicePrefixEnum.OAUTH}/anyone/switchTenantAndOrg`,
    { tenantId, orgId },
    {
      headers: {
        'Content-Type': ContentTypeEnum.FORM_URLENCODED,
      },
    },
  );
}

/**
 * 查找单位和部门
 */
export async function findCompanyDept(tenantId?: null | string) {
  return requestClient.get<UserModel.OrgResultVO>(
    `${ServicePrefixEnum.OAUTH}/anyone/findCompanyDept`,
    {
      params: { tenantId },
    },
  );
}
/**
 * 查找单位和部门
 */
export async function findDeptByCompany(companyId: string, tenantId?: string) {
  return requestClient.get<BaseOrgModel.BaseOrgResultVO>(
    `${ServicePrefixEnum.OAUTH}/anyone/findDeptByCompany`,
    {
      params: { tenantId, companyId },
    },
  );
}
